export default {
  data() {
    const validateStayPat = (rule, value, callback) => {
      if (value < 5 || value > 1440) {
        return callback(new Error('付款等待时间为5-1440分钟'))
      } else {
        callback()
      }
    }

    const validateFinishTime = (rule, value, callback) => {
      if (value < 1 || value > 30) {
        return callback(new Error('自动完结时间为1-30天'))
      } else {
        callback()
      }
    }

    const validateRepTakeTime = (rule, value, callback) => {
      if (value < 1 || value > 15) {
        return callback(new Error('自动收货时间为1-15天'))
      } else {
        callback()
      }
    }

    const validateAutoAppraise = (rule, value, callback) => {
      if (value < 1 || value > 14) {
        return callback(new Error('自动评价时间为1-14天'))
      } else if (value >= this.formData.orderFinishTime) {
        return callback(new Error('自动评价时间需小于自动完成时间'))
      } else {
        callback()
      }
    }

    return {
      rules: {
        orderCancelTime: [
          {
            required: true,
            message: '请输入付款等待时间',
            trigger: 'blur'
          },
          {
            pattern: /^\+?[1-9]\d*$/,
            message: '请输入正整数'
          },
          {
            validator: validateStayPat,
            trigger: 'blur'
          }
        ],

        orderFinishTime: [
          {
            required: true,
            message: '请输入自动完成时间',
            trigger: 'blur'
          },
          {
            pattern: /^\+?[1-9]\d*$/,
            message: '请输入正整数'
          },
          {
            validator: validateFinishTime,
            trigger: 'blur'
          }
        ],
        orderReceiveTime: [
          {
            required: true,
            message: '请输入自动收货时间',
            trigger: 'blur'
          },
          {
            pattern: /^\+?[1-9]\d*$/,
            message: '请输入正整数'
          },
          {
            validator: validateRepTakeTime,
            trigger: 'blur'
          }
        ],
        orderAppraiseTime: [
          {
            required: true,
            message: '请输入自动评价时间',
            trigger: 'blur'
          },
          {
            pattern: /^\+?[1-9]\d*$/,
            message: '请输入正整数'
          },
          {
            validator: validateAutoAppraise,
            trigger: 'blur'
          }
        ],
        newUserGiveMin: [
          {
            required: true,
            message: '请输入最小赠送积分值',
            trigger: 'blur'
          }
        ],
        newUserGiveMax: [
          {
            required: true,
            message: '请输入最大赠送积分值',
            trigger: 'blur'
          }
        ],
        quotaWarn: [
          {
            required: true,
            message: '请输入积分值预警值',
            trigger: 'blur'
          }
        ],
        platformRate: [
          {
            required: true,
            message: '请输入平台服务费抽成比例',
            trigger: 'blur'
          }
        ],
        transactionRate: [
          {
            required: true,
            message: '请输入银联交易手续费抽成比例',
            trigger: 'blur'
          }
        ]
      }
    }
  }
}
